<template>
  <div class="photoinfo-container">
    <h3 class="title">{{photoinfo.title}}</h3>
    <p class="subtitle">
      <span>发表时间:{{photoinfo.add_time|Time}}</span>
      <span>点击:{{photoinfo.click}}次</span>
    </p>
    <hr />
    <!-- 缩略图区域 -->
    <div class="thumbs">
      <vue-preview :slides="list"></vue-preview>
    </div>

    <!-- 图片内容区域 -->
    <div class="content" v-html="photoinfo.content"></div>
    <!-- 评论区域 -->
    <comment :id="id"></comment>
  </div>
</template>
<script>
//按需导入提示组件
import { Toast } from "mint-ui";
// 导入评论组件
import comment from "../subcomponents/comment.vue";
export default {
  data() {
    return {
      id: this.$route.params.id,
      photoinfo: {},
      list: []
    };
  },
  created() {
    this.getphotoinfo();
    this.getthumbs();
  },
  methods: {
    getphotoinfo() {
      this.$https
        .get("http://www.liulongbin.top:3005/api/getimageInfo/" + this.id)
        .then(res => {
          //console.log(res.data);
          if (res.data.status === 0) {
            //成功了
            this.photoinfo = res.data.message[0];
          } else {
            Toast("加载图片详情数据失败");
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    getthumbs() {
      this.$https
        .get("http://www.liulongbin.top:3005/api/getthumimages/" + this.id)
        .then(res => {
          //console.log(res.data);
          if (res.data.status === 0) {
            //成功了
            // 通过循环数组里的每个对象，补全图片的宽和高还有src和msrc属性，构造成 {w: 600, h: 500, src: xxxx, msrc: xxxxxx}
            res.data.message.forEach(item => {
              item.w = 600; //设置以大图浏览时的宽度
              item.h = 400; //设置以大图浏览时的高度
              item.msrc = item.src; //必须设置
              item.src = item.src;
            });
            // 把完整的数据保存到list中
            this.list = res.data.message;
          } else {
            Toast("加载图片详情数据失败");
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
  },
  components: {
    comment
  }
};
</script>
<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
  .title {
    color: #26a2ff;
    text-align: center;
    font-size: 15px;
    margin: 15px 0;
  }
  .subtitle {
    font-size: 13px;
    display: flex;
    justify-content: space-between;
  }
  .content {
    font-size: 13px;
    line-height: 30px; //行间距
  }
  .thumbs {
     /deep/ .my-gallery {
    display: flex;
    flex-wrap: wrap;
    figure {
      width: 30%;
      margin: 5px;
      img {
        width: 100%;
        box-shadow: 0 0 8px #999;
      }
    }
  }
  }
}
</style>